﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyCompany.MyProject.Common;

public static class ConsoleHelper
{
    private static readonly object _objLock = new();

    /// <summary>
    /// 在控制台输出
    /// </summary>
    /// <param name="text"></param>
    /// <param name="color"></param>
    public static void WriteConsoleColor(string text, ConsoleColor color)
    {
        lock (_objLock)
        {
            ConsoleColor consoleColor = Console.ForegroundColor;
            Console.ForegroundColor = color;
            Console.WriteLine(text);
            Console.ForegroundColor = consoleColor;
        }
    }

    /// <summary>
    /// 打印错误消息
    /// </summary>
    /// <param name="text"></param>
    /// <param name="color"></param>
    public static void WriteErrorLine(this string text,ConsoleColor color = ConsoleColor.Red)=>WriteConsoleColor(text, color);
    /// <summary>
    /// 打印警告消息
    /// </summary>
    /// <param name="text"></param>
    /// <param name="color"></param>
    public static void WriteWarningLine(this string text, ConsoleColor color = ConsoleColor.Yellow) => WriteConsoleColor(text, color);
    /// <summary>
    /// 打印普通信息
    /// </summary>
    /// <param name="text"></param>
    /// <param name="color"></param>
    public static void WriteInfoLine(this string text, ConsoleColor color = ConsoleColor.White) => WriteConsoleColor(text, color);
    /// <summary>
    /// 打印成功消息
    /// </summary>
    /// <param name="text"></param>
    /// <param name="color"></param>
    public static void WriteSuccessLine(this string text, ConsoleColor color = ConsoleColor.Green) => WriteConsoleColor(text, color);


}
